package com.zhixue.search.controller;


import com.zhixue.exception.ZhixuePlusException;
import com.zhixue.search.po.CourseIndex;
import com.zhixue.search.service.IndexService;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/index")
public class CourseIndexController {

    @Value("${elasticsearch.course.index}")
    private String courseIndexStore;

    @Autowired
    IndexService indexService;

    @PostMapping("/course")
    public Boolean add(@RequestBody CourseIndex courseIndex) {
        Long id = courseIndex.getId();
        if (id == null) {
            throw new ZhixuePlusException("课程id为空");
        }
        Boolean result = indexService.addCourseIndex(courseIndexStore, String.valueOf(id), courseIndex);
        if (!result) {
            throw new ZhixuePlusException("添加课程索引失败");
        }
        return result;
    }
}
